package com.zyn.qianwen.user.controller;

import com.zyn.qianwen.user.entity.Result;
import com.zyn.qianwen.user.entity.TbLogin;
import com.zyn.qianwen.user.service.UserService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Slf4j
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("login")
    public Result login(@RequestBody TbLogin tbLogin){
        return userService.login(tbLogin);
    }

    @PostMapping("/register")
    @ApiOperation("注册")
    public Result register(@RequestBody TbLogin tbLogin){
        return userService.register(tbLogin);
    }

    /**
     * 展示登录用户信息
     */
    @PostMapping("userInfo")
    @ApiOperation("展示信息")
    public Result userInfo(HttpServletRequest request) throws Exception {
        return userService.userInfo(request);
    }
    /**
     * 退出登录
     */
    @PostMapping("logout")
    @ApiOperation("退出")
    public Result logout(HttpServletRequest request) throws Exception {
        return userService.logout(request);
    }
    @PostMapping("sendCode")
    @ApiOperation("发送短信")
    public Result sendCode(HttpServletRequest request,@RequestBody TbLogin tbLogin) throws Exception {
        return userService.sendCode(request,tbLogin);
    }

}
